<?php 
use think\facade\Db;
 
class Auditors{
    public function TODO($ws,$frame,$fd){
        $param = (array)json_decode($frame->data); 
         
        $filter = [
            '_id'  => $param['_id'], 
        ]; 
        $info = Db::name('friend_apply')->where('status',0)->where($filter)->find();
  
        if($param['opertion'] == true){
            $result =   Db::name('friend_apply')
        
                    ->where($filter)
                    
                    ->update(['status'=>1]); 
             $data = [
                    [
                        "toMember"  => $info['toMember'],
                        'insertTime' =>time(),
                        "memberTo"  => $info['memberTo'],
                        "to_uuid"   => $info['to_uuid'],
                    ],
                    [
                        "toMember"  => $info['memberTo'], 
                        'insertTime' =>time(),
                        "memberTo"  => $info['toMember'],
                        "to_uuid"   => $info['uuid_to'],
                    ]
                    
                ];
        
                
            $isInsert = Db::name('friend')->insertAll($data);  
        }else{
            $result =   Db::name('friend_apply')
        
                        ->where($filter)
                        
                        ->update(['status'=>0]); 
            $isInsert = true;
        }
      
        
                    
        if($result && $isInsert){
            $memberTo = [
                        
                        "toMember"  => $info['memberTo'], 
                        'insertTime' =>time(),
                        "memberTo"  => $info['toMember'],
                        "to_uuid"   => $info['uuid_to'],
                        'msgCount' => 0,
                        '_id'=>$info['_id'],
                        'boolValue'=>$param['opertion'],
                        'object'=>$param['opertion']
                    ]; 
            $return = [
                'status'=>1,
                'msg'=>'申请处理完毕',
                
                'friendData'=>$memberTo,
                'act' => 'Auditors'
            ];
            $toMember= [
                        "toMember"  => $info['toMember'],
                        'insertTime' =>time(),
                        "memberTo"  => $info['memberTo'],
                        "to_uuid"   => $info['to_uuid'],
                        'msgCount' => 0
                    ];
                    var_dump($toMember);
                    var_dump("---------------");
                    var_dump($memberTo);
                    
            $rs = Db::name('user')->where('username',$info['memberTo'])->find(); 
            if(!empty($rs['fd'])){
                var_dump($rs['fd']);
                $returns = [
                    'status'=>1,
                    'msg'=>$info['toMember'].'已通过你的添加申请',
                    'data'=>$toMember, 
                    'act' => 'ToPushAuditors'
                ];
                $ws->push($rs['fd'],json_encode($returns));
            } 
                
                 
        }else{
            $return = [
                'status'=>0,
                'msg'=>'申请处理失败',
                'data'=>'', 
                'act' =>'Auditors'
                
                ];
        }
        return $return;
    }
}